package com.sgb.kjwl.view.ui.adapter;

import android.os.Parcelable;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;

import com.swgk.core.util.PickSelectEntity;

import java.util.ArrayList;
import java.util.List;

public class CommPagerAdapter5 extends FragmentStatePagerAdapter {

    private ArrayList<? extends Fragment> items;
    private List<PickSelectEntity<List<PickSelectEntity>>> channelEntityList;
    private FragmentManager fm;

    public CommPagerAdapter5(FragmentManager fm, ArrayList<? extends Fragment> items, List<PickSelectEntity<List<PickSelectEntity>>> channelEntityList) {
        super(fm);
        this.items = items;
        this.fm = fm;
        this.channelEntityList = channelEntityList;
    }

    @Override
    public int getCount() {
        return items.size() == 0 ? 0 : items.size();
    }

    @Override
    public Fragment getItem(int position) {
        return items.get(position);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return channelEntityList.get(position).getProjectscale();
    }

    @Override
    public int getItemPosition(Object object) {
        return POSITION_NONE;

    }

    @Override
    public Fragment instantiateItem(ViewGroup container, int position) {
        Fragment fragment = (Fragment) super.instantiateItem(container,
                position);
        fm.beginTransaction().show(fragment).commit();
        return fragment;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        // super.destroyItem(container, position, object);
        Fragment fragment = (Fragment) object;
        fm.beginTransaction().hide(fragment).commit();
    }

    @Override
    public Parcelable saveState() {
        return null;
    }
}
